package sort;

import java.util.Arrays;

/**
 * @author huangxin
 * @date 2019/6/25-11:27
 */
public class Test {
    public static void main(String[] args) {

//        System.out.println(Integer.toBinaryString(10));
//        System.out.println(Integer.toBinaryString(14));
//        System.out.println(Integer.toBinaryString(10 | 14));
//        System.out.println(10 | 14);

//        int[] arr = {1, 2, 3, 5, 6, 8};
//
//        int i = find(arr, 8, 0, arr.length - 1);
//        System.out.println(i);

        int[] arr = new int[80000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 8000000);
        }
        long timeMillis1 = System.currentTimeMillis();
        long timeMillis2 = System.currentTimeMillis();
        System.out.println(timeMillis2 - timeMillis1);
        System.out.println(Arrays.toString(arr));
    }





    //二分查找
    static int find(int[] arr, int key, int low, int high) {
        if (arr[low] > key || arr[high] < key || low > high) {
            return -1;
        }

        int middle = (low + high) / 2;
        if (arr[middle] > key) {
            return find(arr, key, low, middle - 1);

        } else if (arr[middle] < key) {
            return find(arr, key, middle + 1, high);
        } else {
            System.out.println("找到   " + arr[middle]);
            return arr[middle];
        }
    }
}
